package com.jackiechan.hello.day08;

import java.io.*;

/**
 * 对myfile.txt文件进行复制操作，要求使用异常捕获
 * 机制对流的异常进行捕获和处理，finally中
 * 要将流关闭
 * @author Xiloer
 *
 */
public class Test01 {
    public static void main(String[] args) throws IOException {
     copy();
    }

    private static void copy() throws IOException {
        File file = new File("D:\\ideaworkspace\\project01\\src\\com\\jackiechan\\hello\\day08\\emp.txt");
        FileInputStream in = new FileInputStream(file);
        if (file.isFile()){
            try {
                File file1 = new File("D:\\ideaworkspace\\project01\\src\\com\\jackiechan\\hello\\day08\\copyemp.txt");
                FileOutputStream out = new FileOutputStream(file1);
                file1.createNewFile();
                for(int i=0;i<file.length();i++){
                    out.write(in.read());
                }
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                in.close();
            }
        }
    }
}
